package com.misakyanls.examples.random;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;

public class NotSortedCollectionMatcher extends TypeSafeMatcher<List<Integer>> {
	@Override
	public void describeTo(Description description) {
		description.appendText("a collection containing values in not sorted order");
	}

	@Override
	public boolean matchesSafely(List<Integer> list) {
		List<Integer> sorted = new ArrayList<Integer>(list); 
		Collections.sort(sorted);
		return !list.equals(sorted);
	}
	
	@Factory
	public static NotSortedCollectionMatcher notSorted() {
        return new NotSortedCollectionMatcher();
    }
}
